package tyc.quartz;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class TycSchedule {
	ExecutorService executor = Executors.newFixedThreadPool(10);

	/*
	 * @Scheduled(cron = "0 0/5 * * * ?") public void task1() { for (int i = 0;
	 * i < 15; i++) { executor.submit(new Runnable() {
	 * 
	 * @Override public void run() { System.out.println("线程===：" +
	 * Thread.currentThread().getName());
	 * 
	 * } }); } }
	 */
	@Scheduled(cron = "0 0/5 * * * ?")
	public void task2() {
		List list=new ArrayList();
		for (int i = 0; i < 15; i++) {
			Future<String> future=executor.submit(new TestTread(i+""));
			list.add(future);
		}
		System.out.println("任务长度："+list.size());
	}
	
	class TestTread implements Callable{
		String name="";
		public TestTread(String name){
			this.name=name;
		}
		@Override
		public Object call() throws Exception {
			Random rd = new Random(10);
			System.out.println(Thread.currentThread().getName() + name + "工作完成了。。。");
			return Thread.currentThread().getName()+"执行了"+name+"任务";
		}
		
	}

}
